#测试首页

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from common.Untils import WJDriver
from selenium.webdriver.common.by import By

class WJHome:
    url = ""
    driver = ""

    def __init__(self):
        self.url = "http://8.155.1.153:8081/home"
        self.driver = WJDriver.driver
        #self.driver.get(self.url)

    #测试页面头部元素
    def TestByHome(self):
        # #验证头像
        # #self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost.ant-page-header-compact > div.ant-page-header-content > div > div > div > div > div > div.avatar___3ZBop > span > img")
        # wjs=self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div.extraContent___3rMo7 > div:nth-child(1) > div > div.ant-statistic-title").text
        # print(wjs+":正常")
        # assert wjs == "问卷数"
        # #验证考试数
        # kss=self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div.extraContent___3rMo7 > div:nth-child(2) > div > div.ant-statistic-title").text
        # print(kss + ":正常")
        # assert kss == "考试数"
        #
        # #验证我的考试存在
        # self.driver.find_element(By.CSS_SELECTOR, "#rc-tabs-1-tab-exam")
        # #print(text+"正常")
        # #assert text == "考试名称"

        # 检查首页标题元素
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > div")
        # 检查问卷数元素
        text=self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div.extraContent___3rMo7 > div:nth-child(1) > div > div.ant-statistic-title").text
        print(text+":正常")
        assert text == "问卷数"
        # 检查考试数元素
        text=self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div.extraContent___3rMo7 > div:nth-child(2) > div > div.ant-statistic-title").text
        print(text + ":正常")
        assert text == "考试数"
        # 检查我的考试按钮
        text=self.driver.find_element(By.CSS_SELECTOR, "#rc-tabs-0-tab-exam").text
        print(text + ":正常")
        assert text == "我的考试"
        # 检查我的问卷按钮
        text=self.driver.find_element(By.CSS_SELECTOR, "#rc-tabs-0-tab-survey").text
        print(text + ":正常")
        assert text == "我的问卷"
        # 检查问卷记录按钮
        text=self.driver.find_element(By.CSS_SELECTOR, "#rc-tabs-0-tab-surveyHistory").text
        print(text + ":正常")
        assert text == "问卷记录"
        # 检查考试记录按钮
        text=self.driver.find_element(By.CSS_SELECTOR, "#rc-tabs-0-tab-examHistory").text
        print(text + ":正常")
        assert text == "考试记录"
        # 检查创建问卷按钮
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-col.ant-col-xs-24.ant-col-sm-24.ant-col-md-24.ant-col-lg-24.ant-col-xl-8 > div > div.ant-card-body > div > a:nth-child(1)")
        # 检查创建考试按钮
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-col.ant-col-xs-24.ant-col-sm-24.ant-col-md-24.ant-col-lg-24.ant-col-xl-8 > div > div.ant-card-body > div > a:nth-child(2)")

        wait = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,
                                                                                      "#sk-layout > div > div > section > div.ant-pro-layout-container > header.ant-layout-header.ant-pro-layout-header.ant-pro-layout-header-fixed-header.ant-pro-layout-header-mix.ant-pro-layout-header-fixed-header-action.ant-pro-layout-header-header > div > div.ant-pro-global-header-right-content > div > div > div > div:nth-child(2) > span")))
        self.driver.find_element(By.CSS_SELECTOR,"#sk-layout > div > div > section > div.ant-pro-layout-container > header.ant-layout-header.ant-pro-layout-header.ant-pro-layout-header-fixed-header.ant-pro-layout-header-mix.ant-pro-layout-header-fixed-header-action.ant-pro-layout-header-header > div > div.ant-pro-global-header-right-content > div > div > div > div:nth-child(2) > span").click()
        wait = WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR,
                                                                                      "body > div:nth-child(8) > div > div > ul > li.ant-dropdown-menu-item.ant-dropdown-menu-item-active")))
        self.driver.find_element(By.CSS_SELECTOR,"body > div:nth-child(8) > div > div > ul > li.ant-dropdown-menu-item.ant-dropdown-menu-item-active").click()


# home=WJHome()
# home.TestByHead()